﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DealKhuyenMaiV2.com.Models;

namespace DealKhuyenMaiV2.com.Controllers
{
    [DealKhuyenMaiV2.com.Controllers.AccountController.AdminAuthorize]
    public class TypeAccountController : BaseController
    {
        //
        // GET: /TypeAccount/

        public ViewResult Index()
        {
            var result = from typeAc in DbConText.TypeAccounts where typeAc.NameTypeAccount != "admin" select typeAc;
            return View(result.ToList());
        }

        //
        // GET: /TypeAccount/Details/5

        public ViewResult Details(int id)
        {
            TypeAccount typeaccount = DbConText.TypeAccounts.Single(t => t.IDTypeAccount == id);
            return View(typeaccount);
        }

        //
        // GET: /TypeAccount/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /TypeAccount/Create

        [HttpPost]
        public ActionResult Create(TypeAccount typeaccount)
        {
            if (ModelState.IsValid)
            {
                DbConText.TypeAccounts.AddObject(typeaccount);
                DbConText.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(typeaccount);
        }

        //
        // GET: /TypeAccount/Edit/5

        public ActionResult Edit(int id)
        {
            TypeAccount typeaccount = DbConText.TypeAccounts.Single(t => t.IDTypeAccount == id);
            return View(typeaccount);
        }

        //
        // POST: /TypeAccount/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, TypeAccount typeaccount)
        {
            TypeAccount _typeaccount = DbConText.TypeAccounts.Single(t => t.IDTypeAccount == id);
            {
                _typeaccount.NameTypeAccount = typeaccount.NameTypeAccount;
            }
            if (ModelState.IsValid)
            {
                return RedirectToAction("Index");
            }
            return View(typeaccount);
        }


        //GET: /TypeAccount/Delete/5

        public ActionResult Delete(int id)
        {
            TypeAccount typeaccount = DbConText.TypeAccounts.Single(t => t.IDTypeAccount == id);
            DbConText.TypeAccounts.DeleteObject(typeaccount);
            DbConText.SaveChanges();
            return RedirectToAction("Index");
        }

        //
        // POST: /TypeAccount/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            TypeAccount typeaccount = DbConText.TypeAccounts.Single(t => t.IDTypeAccount == id);
            DbConText.TypeAccounts.DeleteObject(typeaccount);
            DbConText.SaveChanges();
            return RedirectToAction("Index");
        }
    }
}